function varargout = GUI_gyr(varargin)
%GUI_GYR MATLAB code file for GUI_gyr.fig
%      GUI_GYR, by itself, creates a new GUI_GYR or raises the existing
%      singleton*.
%
%      H = GUI_GYR returns the handle to a new GUI_GYR or the handle to
%      the existing singleton*.
%
%      GUI_GYR('Property','Value',...) creates a new GUI_GYR using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to GUI_gyr_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      GUI_GYR('CALLBACK') and GUI_GYR('CALLBACK',hObject,...) call the
%      local function named CALLBACK in GUI_GYR.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_gyr

% Last Modified by GUIDE v2.5 11-Jul-2018 22:51:07

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_gyr_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_gyr_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GUI_gyr is made visible.
function GUI_gyr_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for GUI_gyr
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

cla

%Show image of the sensor's positions
myImage = imread('image.png');
set(handles.axes2,'Units','pixels');
resizePos = get(handles.axes2,'Position');
%myImage= imresize(myImage, [resizePos(3) resizePos(3)]);
axes(handles.axes2);
imshow(myImage);
set(handles.axes2,'Units','normalized');

%initialise les données
Data = [];
handles.Data = Data;
disp(Data)
guidata(hObject, handles)

%charges les données dernièrement sauvegardées
disp(1)
Data = handles.Data;
disp(2)
load('GUI','Data')
disp(3)
handles.Data = Data;

%set(handles.Data);
guidata(hObject, handles)

% UIWAIT makes GUI_gyr wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_gyr_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in Charger_pushbutton.
function Charger_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Charger_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%Initilalise les données 
Data = [];
handles.Data = Data;
disp(Data)
guidata(hObject, handles)

%charges les données dernièrement sauvegardées
disp(1)
Data = handles.Data;
disp(2)
load('GUI','Data')
disp(3)
handles.Data = Data;

%set(handles.Data);
guidata(hObject, handles)


% --- Executes on button press in Sauvegarder_pushbutton.
function Sauvegarder_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Sauvegarder_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp(1)
Data = handles.Data;
disp(2)
save('GUI','Data')
disp(3)
handles.Data = Data;

%Enregister les données pour les passer entre les fonctions
guidata(hObject, handles)


% --- Executes on button press in Affichage_pushbutton.
function Affichage_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Affichage_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp(1)
Data = handles.Data;
disp(2)

% Create axes
axe = handles.axes1;
axes(axe);
a = Data.Gyr.a;
b = Data.Gyr.b;
Second_sB = Data.Capteur(a).Gyr.Second;
Angle_f = Data.Capteur(a).Gyr.Angle;
plot(Second_sB,Angle_f, '-')
title('Angle entre les deux capteurs, gyroscope','FontSize', 18)
ylabel('Angle (deg)','FontSize', 18)
xlabel('Temps (s)','FontSize', 18)

disp(3)
handles.Data = Data;

guidata(hObject, handles)    



function Fc_edit_Callback(hObject, eventdata, handles)
% hObject    handle to Fc_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Fc_edit as text
%        str2double(get(hObject,'String')) returns contents of Fc_edit as a double
Fc = str2double(get(hObject, 'String'));
if isnan(Fc)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

% Save the offset value
Data = handles.Data;
Data.Gyr.Fc = Fc;
handles.Data = Data;
disp(handles.Data.Gyr.Fc)
guidata(hObject, handles)


% --- Executes during object creation, after setting all properties.
function Fc_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Fc_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Offset_edit_Callback(hObject, eventdata, handles)
% hObject    handle to Offset_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Offset_edit as text
%        str2double(get(hObject,'String')) returns contents of Offset_edit as a double
offset = str2double(get(hObject, 'String'));
if isnan(offset)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

% Save the offset value
Data = handles.Data;
Data.Gyr.Offset = offset;
handles.Data = Data;
disp(handles.Data.Gyr.Offset)
guidata(hObject, handles)  


% --- Executes during object creation, after setting all properties.
function Offset_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Offset_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in Angle_pushbutton.
function Angle_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Angle_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp(1)
Data = handles.Data;
disp(2)

Data = IntegrationFiltre(Data);

disp(3)
handles.Data = Data;
guidata(hObject, handles)    
